package com.gotye.hockeygame.objects;

import android.opengl.GLES20;

import com.gotye.hockeygame.Constants;
import com.gotye.hockeygame.data.VertexArray;
import com.gotye.hockeygame.programs.ColorShaderProgram;
import com.gotye.hockeygame.objects.ObjectBuilder.DrawCommand;
import com.gotye.hockeygame.objects.ObjectBuilder.GeneratedData;
import com.gotye.hockeygame.util.Geometry.Point;

import java.util.List;

/**
 * Created by Michael.Ma on 2016/3/3.
 */
public class Mallet {
    private static final int POSITION_COMPONENT_COUNT = 3;

    public float radius;
    public float height;

    private final VertexArray vertexArray;
    private List<DrawCommand> drawList;

    public Mallet(float radius, float height, int numPointsAroundMallet) {
        GeneratedData generatedData = ObjectBuilder.createMallet(
                new Point(0f, 0f, 0f), radius, height, numPointsAroundMallet);
        this.radius = radius;
        this.height = height;
        vertexArray = new VertexArray(generatedData.vertexData);
        drawList = generatedData.drawList;
    }

    public void bindData(ColorShaderProgram colorProgram) {
        vertexArray.setVertexAttribPointer(
                0,
                colorProgram.getPositionAttributeLocation(),
                POSITION_COMPONENT_COUNT,
                0);
    }

    public void draw() {
        for (DrawCommand drawCommand : drawList) {
            drawCommand.draw();
        }
    }
}
